classdef GameModel
    %UNTITLED4 Summary of this class goes here
    %   Detailed explanation goes here
    
    properties
       targets
       defenderCoveredPayoffs
       defenderUncoveredPayoffs
       attackerCoveredPayoffs
       attackerUncoveredPayoffs
       coverageVector
       resources
    end
    
    methods
        
        function model=GameModel(arg)
            if nargin==1 % Used when objects are loaded from disk
              
              return;
            end 
            if nargin == 0
                mod= generateRandomModel(model,25);
                model.targets=mod.targets;
                model.defenderCoveredPayoffs= mod.defenderCoveredPayoffs;
                model.defenderUncoveredPayoffs=mod.defenderUncoveredPayoffs;
                model.attackerCoveredPayoffs=mod.attackerCoveredPayoffs;
                model.attackerUncoveredPayoffs=mod.attackerUncoveredPayoffs;
                model.coverageVector=mod.coverageVector;
                return
            end
        end
        
        function inter=getDefenderPayoff(target)
           
        end
        
        function inter=getAttackerPayoff(target)
            
        end
        
        function setCoverageValue(target,value)
        end
        
        function model=generateRandomModel(obj,N)
           uncertaintyLevel=0.3;
           Ud1=-rand(1,N)*100;
           Ud2=-rand(1,N)*100;

           Ucd=max(Ud1(1,:),Ud2(1,:));
           Uud=min(Ud1(1,:),Ud2(1,:)); 


           Ua1=rand(1,N)*50;
           Ua2=rand(1,N)*50;

           Uca=max(Ua1(1,:),Ua2(1,:));
           Uua=min(Ua1(1,:),Ua2(1,:)); 

           Dist=Uca-Uua;

           uncertaintyCoef=Dist*uncertaintyLevel;

           uncertU=rand(1,N).*uncertaintyCoef;
           uncertC=rand(1,N).*uncertaintyCoef;


           UuaMax=Uua+uncertU+50;
           UuaMin=Uua-uncertU+50;

           UcaMax=Uca+uncertC+50;
           UcaMin=Uca-uncertC+50;
           
           model.targets=1:N;
           
           
           for i=1:N
              model.defenderCoveredPayoffs(i)=Interval(Ucd(i),Ucd(i), strcat('edc',num2str(i))); 
              model.defenderUncoveredPayoffs(i)=Interval(Uud(i),Uud(i), strcat('edu',num2str(i))); 
              model.attackerCoveredPayoffs(i)=Interval(UcaMin(i),UcaMax(i), strcat('eac',num2str(i))); 
              model.attackerUncoveredPayoffs(i)=Interval(UuaMin(i),UuaMax(i), strcat('eau',num2str(i)));
              model.coverageVector(i)=Interval(0,0,strcat('cov',num2str(i)));
           end
           
          
           
        end
        
        
        
    
		function isg_model = prepareForIsg(model)
			isg_model.targets=model.targets;
			isg_model.Uud   =Utils.convertToArray(model.defenderUncoveredPayoffs, 'min');
		    isg_model.Ucd   =Utils.convertToArray(model.defenderCoveredPayoffs, 'min');
			isg_model.UuaMin=Utils.convertToArray(model.attackerUncoveredPayoffs, 'min');
			isg_model.UuaMax=Utils.convertToArray(model.attackerUncoveredPayoffs, 'max');
			isg_model.UcaMin=Utils.convertToArray(model.attackerCoveredPayoffs, 'min');
			isg_model.UcaMax=Utils.convertToArray(model.attackerCoveredPayoffs, 'max');
			isg_model.coverageVector=zeros(1,length(model.targets));
		end
        
		function interval_sg_model=prepareForIntervalSg(model)
			
            interval_sg_model.targets=model.targets;
			interval_sg_model.Uud =model.defenderUncoveredPayoffs;
		    interval_sg_model.Ucd=model.defenderCoveredPayoffs;
			interval_sg_model.Uua=model.attackerUncoveredPayoffs;
			interval_sg_model.Uca=model.attackerCoveredPayoffs;
			interval_sg_model.coverageVector=model.coverageVector;
		end
		
		function sg_model = prepareForSg(model)
			sg_model.targets=model.targets;
			sg_model.Uud =Utils.convertToArray(model.defenderUncoveredPayoffs, 'min');
		    sg_model.Ucd=Utils.convertToArray(model.defenderCoveredPayoffs, 'min');
			sg_model.Uua=Utils.convertToArray(model.attackerUncoveredPayoffs, 'random');
			sg_model.Uca=Utils.convertToArray(model.attackerCoveredPayoffs, 'random');
			sg_model.coverageVector=zeros(1,length(model.targets));
		end
		
		function affine_model = prepareForAffine(model)
			affine_model.targets=model.targets;
			affine_model.Uud =Utils.convertToAffineArray(model.defenderUncoveredPayoffs);
		    affine_model.Ucd=Utils.convertToAffineArray(model.defenderCoveredPayoffs);
			affine_model.Uua=Utils.convertToAffineArray(model.attackerUncoveredPayoffs);
			affine_model.Uca=Utils.convertToAffineArray(model.attackerCoveredPayoffs);
			affine_model.coverageVector=Utils.convertToAffineArray(model.coverageVector);
		end
		
        
    end
    
end

